﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Web;

namespace HynuIOTA.Respository
{
    public static class EFFactory
    {
        /// <summary>
        /// 从Http上下文中获取EF容器
        /// </summary>
        /// <returns></returns>
        public static HynuIOTAEntitiesContainer GetDBContext()
        {
            var context = HttpContext.Current.Items[nameof(HynuIOTAEntitiesContainer)] as HynuIOTAEntitiesContainer;
            if (context == null)
            {
                context = new HynuIOTAEntitiesContainer();
                HttpContext.Current.Items[nameof(HynuIOTAEntitiesContainer)] = context;
            }

            return context as HynuIOTAEntitiesContainer;
        }
    }
}
